#!/usr/bin/python

import os
import numpy
from collections import Counter
from pylab import *
import tables,scipy
from scipy import fftpack
from scipy.cluster import vq
from scipy.ndimage import morphology,filters,interpolation
from ocrolib import docproc,improc
import pyflann
import random
import tables
from multiprocessing import Pool
import fcntl
from pdb import pm
from llpy.sutils import *
import unicodedata

import argparse
parser = argparse.ArgumentParser( description = "Show character statistics.")
parser.add_argument('inputs',default=[],help="data file",nargs="*")
args = parser.parse_args()


totals = Counter()

for fname in args.inputs:
    with tables.openFile(fname) as db:
        nsamples = len(db.root.classes)
        classes = array(db.root.classes[:nsamples],'i')
    totals += Counter(classes)

for c,n in totals.most_common():
    c = udecode(c)
    if c in [" ","\t","\r","\n","_"]: continue
    print "%-3s %8d"%(c,n)
